package com.plants.back.controller;

import com.plants.back.pojo.Home;
import com.plants.back.pojo.Vo;
import com.plants.back.service.impl.PlantsGoodsServiceImpl;
import com.plants.back.service.impl.PlantsNewsServiceImpl;
import com.plants.back.service.impl.PlantsOrdersServiceImpl;
import com.plants.back.service.impl.PlantsUserServiceImpl;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("plants_home")
public class PlantsHomeController {

    @Resource
    private PlantsOrdersServiceImpl ordersService;

    @Resource
    private PlantsGoodsServiceImpl goodsService;

    @Resource
    private PlantsNewsServiceImpl newsService;

    @Resource
    private PlantsUserServiceImpl userService;

    @GetMapping
    public Vo<Home> home(){
        Integer order_count = ordersService.count();
        Integer goods_count = goodsService.count();
        Integer news_count = newsService.count();
        Integer user_count = userService.count();
        Home home = new Home();
        home.setOrders_count(String.valueOf(order_count));
        home.setGoods_count(String.valueOf(goods_count));
        home.setNews_count(String.valueOf(news_count));
        home.setUser_count(String.valueOf(user_count));
        return new Vo<>(true,home);
    }
}
